package cn.iocoder.yudao.module.promotion.redpacket.dao;

import cn.iocoder.yudao.framework.business.basic.dao.mapper.CoreMapper;
import cn.iocoder.yudao.framework.business.basic.dao.query.CoreLambdaQueryWrapper;
import cn.iocoder.yudao.module.promotion.redpacket.pojo.po.RedPacketActivity;
import org.apache.ibatis.annotations.Mapper;

import java.time.LocalTime;

/**
 * <pre>
 * OOoO0OOoO0OOOooo0oOOOO0OOOOO0oooOO0ooOOO0Ooooo0OOOOo0ooooO0OOooo0Ooooo0OOOOO
 * Mapper 接口
 * OOoO0OOoO0OOOooo0oOOOO0OOOOO0oooOO0ooOOO0Ooooo0OOOOo0ooooO0OOooo0Ooooo0OOOOO
 * </pre>
 *
 * @author 山野羡民（1032694760@qq.com）
 * @since 2025/06/21
 */
@Mapper
public interface RedPacketActivityMapper extends CoreMapper<RedPacketActivity> {

    default RedPacketActivity selectMatchedOne(Long shopId, Integer orderAmount, LocalTime time) {
        return selectOne(new CoreLambdaQueryWrapper<RedPacketActivity>()
                .eq(RedPacketActivity::getEnable, true)
                .lt(RedPacketActivity::getStartTime, time)
                .gt(RedPacketActivity::getEndTime, time)
                .eq(RedPacketActivity::getShopId, shopId)
                .le(RedPacketActivity::getThresholdPrice, orderAmount)
                .orderByDesc(RedPacketActivity::getId));
    }

}
